/**
 * Copyright (c) 2015-2016
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.tyf.common.config;

import com.tyf.common.dao.DaoHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;

import javax.persistence.EntityManagerFactory;

/**
 * @author xd<br>
 * @ClassName: CommonCoreConfiguration<br>
 * @Description: common-core 工程 Bean 相关配置<br>
 * @date Jul 9, 2016 8:14:03 PM<br>
 */
@Configuration
public class CommonCoreConfiguration {

    @Bean
    public Object getConversionService() {
        FormattingConversionServiceFactoryBean factoryBean = new FormattingConversionServiceFactoryBean();
        return factoryBean;
    }


    //MethodInvokingFactoryBean是为对象的静态变量进行注入
    @Bean
    public MethodInvokingFactoryBean methodInvokingFactoryBeanSearch() {
        MethodInvokingFactoryBean mfBean = new MethodInvokingFactoryBean();
        mfBean.setStaticMethod("com.tyf.common.domain.search.utils.SearchableConvertUtils.setConversionService");

        mfBean.setArguments(new Object[]{getConversionService()});
        return mfBean;
    }

    @Bean
    @Autowired
    public MethodInvokingFactoryBean methodInvokingFactoryBeanRepository(EntityManagerFactory entityManagerFactory) {
        MethodInvokingFactoryBean mfBean = new MethodInvokingFactoryBean();
        mfBean.setStaticMethod("com.tyf.common.dao.DaoHelper.setEntityManagerFactory");
        mfBean.setArguments(new Object[]{entityManagerFactory});
        return mfBean;
    }

}
